{/* LAYOUT模板 */}
	<layout name="layout"/>
{/* LAYOUT模板 */}
{/* import Js,Css */}
	<js href="__PUBLIC__/js/admin/listTable.js"/>
	<js href="__PUBLIC__/js/admin/js.util.js"/>
	<css href="__PUBLIC__/css/admin/common.css"/>
	<js href="__PUBLIC__/js/admin/js.selectzone.js"/>
	
	<css href="__PUBLIC__/css/jquery-ui.css" />
	<js href="__PUBLIC__/js/jquery-ui.1.10.4.js" />
	<js href="__PUBLIC__/js/core/plugins.js"/>
{/* import js,css */}
<!-- [position] -->
	<include file="Template:position"/>
<!-- [position] -->

<div class="main-div">
	<form method="post" action="__URL__/{$action}" name="theForm" onsubmit="return validate()">
		<table cellspacing="1" cellpadding="3" width="100%">
			<tr>
				<td class="label" align="right">超值礼包名称</td>
				<td>
					<input type="text" name="package_name" maxlength="60" size="40" value="{$package.package_name}" />
					*
				</td>
			</tr>
			<tr>
				<td class="label" align="right">活动开始时间</td>
				<td>
					<input type="text" name="start_time" maxlength="60" size="40" value="{$package.start_time}" readonly="readonly" id="start_time_id" />
					*
				</td>
			</tr>
			<tr>
				<td class="label" align="right">活动结束时间</td>
				<td>
					<input type="text" name="end_time" maxlength="60" size="40" value="{$package.end_time}"  readonly="readonly" id ="end_time_id" />				
					*
				</td>
			</tr>
			<tr>
				<td class="label" align="right">
					<a href="javascript:showNotice('noticepackagePrice');" title="{$lang.form_notice}">
						<img src="__PUBLIC__/image/admin/notice.gif" width="16" height="16" border="0" alt="{$lang.form_notice}">
					</a>
					{$Think.lang.package_price}
				</td>
				<td>
					<input type="text" name="package_price" maxlength="60" size="20" value="{$package.package_price}" />
					{$Think.lang.require_field}<br/>
					<span class="notice-span" <if condition="$help_open">style="display:block"<else/> style="display:none"</if> id="noticepackagePrice">{$lang.notice_package_price}</span>
				</td>
			</tr>
			<tr>
				<td class="label" align="right">{$Think.lang.desc}</td>
				<td><textarea  name="desc" cols="60" rows="4">{$package.act_desc}</textarea></td>
			</tr>
			<!-- 商品搜索 -->
			<tr>
				<td class="label" align="right">
					{$Think.lang.search_goods}
				</td>
				<td>
					<select name="cat_id">
						<option value="0">{$Think.lang.all_category}</option>
						<volist name="cat_list" id="cat">
						<option value="{$cat.cat_id}">{$cat.cat_name}</option>
						</volist>
					</select>
					<select name="brand_id">
						<option value="0">{$Think.lang.all_brand}</option>
						<volist name="brand_list" id="brand">
							<option value="{$key}">{$brand}</option>
						</volist>
					</select>
					<input type="text" name="keyword" />
					<input type="button" value="搜索" onclick="javascript:searchGoods();"  />
				</td>
			</tr>
			<tr>
				<td colspan="2">
					<table id="groupgoods-table" align="center" style="width:70%;">
						<!-- 商品列表 -->
						<tr>
							<th>{$Think.lang.all_goods}</th>
							<th>{$Think.lang.handler}</th>
							<th>{$Think.lang.package_goods}</th>
						</tr>
						<tr>
							<td width="42%">
								<select name="source_select" size="15" style="width:100%" onchange="this.form.elements['number'].value = 1" ondblclick="sz.addItem(false, 'add_package_goods', this.form.elements['id'].value, this.form.elements['number'].value)">
								</select>
							</td>
							<td align="center">
								<p>
									{$Think.lang.goods_number}<br />
									<input name="number" type="text" size="6" value="1" />
								</p>
								<p><input type="button" value=">>" onclick="sz.addItem(true, 'add_package_goods', this.form.elements['id'].value, this.form.elements['number'].value)"  /></p>
								<p><input type="button" value=">" onclick="sz.addItem(false, 'add_package_goods', this.form.elements['id'].value, this.form.elements['number'].value)"  /></p>
								<p><input type="button" value="<" onclick="sz.dropItem(false, 'drop_package_goods', this.form.elements['id'].value)"  /></p>
								<p><input type="button" value="<<" onclick="sz.dropItem(true, 'drop_package_goods', this.form.elements['id'].value)"  /></p>
							</td>
							<td width="42%">
								<select name="target_select" size="15" style="width:100%" multiple ondblclick="sz.dropItem(false, 'drop_package_goods', this.form.elements['id'].value)">
									<volist name="package_goods_list" id="package_goods">
										<option value="{$package_goods.g_p}">{$package_goods.goods_name}</option>
									</volist>
								</select>
							</td>
						</tr>
					</table>
				</td>
			</tr>
			<tr>
				<td colspan="2" align="center">
				<input type="submit" value="{$Think.lang.button_submit}"  />
				<input type="reset" value="{$Think.lang.button_reset}"  />
				<input type="hidden" name="act" value="{$form_action}" />
				<input type="hidden" name="id" value="{$package.id}" />
				</td>
			</tr>
		</table>
	</form>
</div>


<script language="JavaScript">

document.forms['theForm'].elements['package_name'].focus();
var elements 	= 	document.forms['theForm'].elements;
var sz 			= 	new SelectZone(2, elements['source_select'], elements['target_select'], elements['number']);
onload = function(){
    // 开始检查订单
    //startCheckOrder();
}

/**
 * 检查表单输入的数据
 */
function validate()
{
    validator = new Validator("theForm");
    validator.required("package_name",  no_name);
    //validator.isNullOption("goods_id", no_goods_id);
    validator.isTime("start_time", invalid_starttime, true);
    validator.isTime("end_time", invalid_endtime, true);
    validator.gt("end_time", "start_time", invalid_gt);
    validator.isNumber("package_price", invalid_package_price, true);

    if (document.forms['theForm'].elements['act'] == "insert")
    {
        validator.required("password", no_password);
    }

    return validator.passed();
}

function searchGoods()
{
    var filter = new Object;
    filter.keyword    = document.forms['theForm'].elements['keyword'].value;
    filter.cat_id     = document.forms['theForm'].elements['cat_id'].value;
    filter.brand_id   = document.forms['theForm'].elements['brand_id'].value;

    //Ajax.call('package.php?is_ajax=1&act=search_goods', filter, searchGoodsResponse, 'GET', 'jsON')
	$.ajax({
		url:'__URL__/search_goods',
		type:'get',
		dataType:'json',
		data:{'jsON':filter},
		beforeSend:function(){},
		success:function(result){
			searchGoodsResponse(result);
		}
	});
}

function searchGoodsResponse(result)
{
  var frm = document.forms['theForm'];
  var sel = frm.elements['source_select'];

  if (result.error == 0)
  {
    /* 清除 options */
    sel.length = 0;

    /* 创建 options */
    var goods = result.content;
    if (goods)
    {
        for (i = 0; i < goods.length; i++)
        {
            /* 货品 options */
            if (goods[i].products.length > 0)
            {
              for (var j = 0; goods[i].products[j]; j++)
              {
                var opt = document.createElement("OPTION");
                opt.value = goods[i].value + '_' + goods[i].products[j].product_id;
                opt.text  = goods[i].text + '[' + goods[i].products[j].goods_attr_str + ']';
                sel.options.add(opt);
              }
            }
            else
            {
              var opt = document.createElement("OPTION");
              opt.value = goods[i].value;
              opt.text  = goods[i].text;
              sel.options.add(opt);
            }
        }
    }
    else
    {
        var opt = document.createElement("OPTION");
        opt.value = 0;
        opt.text  = search_is_null;
        sel.options.add(opt);
    }
  }

  if (result.message.length > 0)
  {
    alert(result.message);
  }
}


</script>